#!/bin/bash

#Control Center for BigLinux
#
#Authors:
#  Bruno Goncalves Araujo <www.biglinux.com.br>
#
#License: GPLv2 or later
#################################################

#Include personal configuration and theme
mkdir ~/.bigcontrolcenter 2> /dev/null

. /usr/share/bigcontrolcenter/default/theme.sh

#Translation
export TEXTDOMAINDIR="/usr/share/locale-langpack"
export TEXTDOMAIN=bigcontrolcenter 

echo '  <style> <!--
    body { background-image: url("/usr/share/bigcontrolcenter/default/images/body-background.png");
	   background-attachment : fixed; }
  --></style>
<script language="JavaScript">
window.resizeTo(660,480);
function NoResize(){
  window.resizeTo(660,480);
}
</script>
</head>
<body onResize="NoResize();">
'

bigbash_header

echo "<title>" $"Centro de Controle Big" "</title>"
cat << EOF
	<link type="text/css" href="/usr/share/bigcontrolcenter/default/css/jquery/ui.all.css" rel="stylesheet" />
	<script type="text/javascript" src="/usr/share/bigcontrolcenter/default/js/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="/usr/share/bigcontrolcenter/default/js/ui/ui.core.js"></script>
	<script type="text/javascript" src="/usr/share/bigcontrolcenter/default/js/ui/ui.tabs.js"></script>

	<script type="text/javascript">
	\$(function() {
		\$("#tabs").tabs({
			event: 'mouseover'
		})
	});

	if (document.images) {
	buttonUp = new Image(); buttonUp.src = "/usr/share/bigcontrolcenter/default/images/category-background.png";
	buttonDown = new Image(); buttonDown.src = "$(echo $HOME)/.bigcontrolcenter/category-background-over.png";
	}

	function turn_off(cell) {
	if (document.images != null) {
	cell.style.backgroundImage = "url('" + buttonUp.src + "')";
	}
	}

	function turn_on(cell) {
	if (document.images != null) {
	cell.style.backgroundImage = "url('" + buttonDown.src + "')";
	}
	}

  </script>
<style>
a:link {color: $(grep "^Palette.active=" ~/.config/Trolltech.conf | cut -f7 -d ",")}
a:hover {text-decoration: underline;}
</style>



<div id="tabs" align="center">
	<ul>
		<li><a href="#tabs-1"><img src="/usr/share/bigcontrolcenter/default/images/icons/internet.png"><br>Internet</a></li>
		<li><a href="#tabs-2"><img src="/usr/share/bigcontrolcenter/default/images/icons/hardware.png"><br>Hardware</a></li>
		<li><a href="#tabs-3"><img src="/usr/share/bigcontrolcenter/default/images/icons/system.png"><br>Sistema</a></li>
		<li><a href="#tabs-4"><img src="/usr/share/bigcontrolcenter/default/images/icons/themes.png"><br>Design</a></li>
		<li><a href="#tabs-5"><img src="/usr/share/bigcontrolcenter/default/images/icons/servers.png"><br>Servidores</a></li>
		<li><a href="#tabs-6"><img src="/usr/share/bigcontrolcenter/default/images/icons/other.png"><br>Outros</a></li>
		<li><a href="#tabs-7"><img src="/usr/share/bigcontrolcenter/default/images/icons/help.png"><br>Ajuda</a></li>
	</ul>
EOF



function make_categories()
{
cd /usr/share/bigcontrolcenter/categories/$2
rm -f ~/.bigcontrolcenter/cat$1ordem.html
echo "<div id=\"tabs-$1\"><TABLE align=center><tr><td>"
n=0
  for b in $(ls)
  do
    . /usr/share/bigcontrolcenter/categories/$2/$b/description.sh
echo "$name_application~$b" >> ~/.bigcontrolcenter/cat$1ordem.html
done
  for i in $(sort ~/.bigcontrolcenter/cat$1ordem.html | cut -d~ -f2)
  do
    . /usr/share/bigcontrolcenter/categories/$2/$i/description.sh
    echo "<a href=\"$exec_application\"" "$mouseover_open" $description_application "$mouseover_close>""<table onmouseout=\"turn_off(this)\" onmouseover=\"turn_on(this)\" $bigbash_categories_background_config background=$bigbash_categories_background><tr><td width=30><img src=$icon_application></td>"'<td valign="middle">'"$bigbash_categories_font $name_application </font></td></tr></table></a><font size=1px><p></font>"

#Duas colunas
    n=$((n+1))
    if [ "$(($n%2))" = "0" ]; then
      echo '</td></tr><tr><td>'
    else
      echo '</td><td width=100%></td><td>'
    fi
  done

  if ! [ -e ~/.bigcontrolcenter/cat$1ordem.html ] 
  then
    echo '<center>'$"Nenhum item encontrado nessa categoria" '</center>'
  fi
echo '</table></div>'
}

make_categories 1 internet
make_categories 2 hardware
make_categories 3 system
make_categories 4 themes
make_categories 5 servers
make_categories 6 others
make_categories 7 help


